﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;
using FluentNHibernate.Automapping;
using FluentNHibernate.Cfg;
using FluentNHibernate.Cfg.Db;
using LumenLiquid.Database.Mappings;
using NHibernate;
using NHibernate.Tool.hbm2ddl;
using LumenLiquid.Database.Entities;

namespace LumenLiquid.Database
{
    internal static class SessionFactory
    {
        public static ISessionFactory CreateSettingsSessionFactory()
        {
            return Fluently.Configure()
                .Database(SQLiteConfiguration.Standard
                              .UsingFile(Path.Databases.DbSettings))
                .Mappings(m => m.FluentMappings
                                   .Add<PropertiesMap>()
                                   .Add<SavegameInfoMap>()
                                   .Add<LanguageInfoMap>()
                                   .Add<WorldInfoMap>())
                .ExposeConfiguration(
                    cfg => new SchemaExport(cfg.SetInterceptor(new DatabaseDebugger("settings"))).Create(false, false))
                .BuildSessionFactory();
        }

        public static ISessionFactory CreateLanguageSessionFactory()
        {
            return Fluently.Configure()
                .Database(SQLiteConfiguration.Standard
                              .UsingFile(Path.Databases.DbLanguage))
                .Mappings(m => m.FluentMappings
                                   .Add<TranslationMap>())
                .ExposeConfiguration(
                    cfg => new SchemaExport(cfg.SetInterceptor(new DatabaseDebugger("language"))).Create(false, false))
                .BuildSessionFactory();
        }

        public static ISessionFactory CreateWorldSessionFactory(string world)
        {
            return Fluently.Configure()
                .Database(SQLiteConfiguration.Standard
                              .UsingFile(Path.Databases.DbWorldPath + world + "\\world.lldb"))
                .Mappings(m => m.FluentMappings
                                   .Add<PropertiesMap>()
                                   .Add<TeleporterMap>()
                                   .Add<MapInfoMap>())
                .ExposeConfiguration(
                    cfg => new SchemaExport(cfg.SetInterceptor(new DatabaseDebugger("world " + world))).Create(false, false))
                .BuildSessionFactory();
        }
    }
}
